{extend name="../../common/view/admin_base"/}

{block name="main"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-form">
                        <div class="layui-form-item layui-hide">
                            <label class="layui-form-label">guid</label>
                            <div class="layui-input-inline" style="width:260px;">
                                <input type="text" name="form[guid]" value="{$model.guid|default=''}" autocomplete="off" placeholder="" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">字段名</label>
                            <div class="layui-input-inline" style="width:160px;">
                                <input type="text" name="form[name]" value="{$model.name|default=''}" autocomplete="off" placeholder="" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">在数据库中的名称</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">名称</label>
                            <div class="layui-input-inline" style="width:120px;">
                                <input type="text" name="form[title]" value="{$model.title|default=''}" autocomplete="off" placeholder="" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">在表单中显示的名称</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">提示</label>
                            <div class="layui-input-inline" style="width:200px;">
                                <input type="text" name="form[remark]" value="{$model.remark|default=''}" autocomplete="off" placeholder="" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">字段提示</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">验证规则</label>
                            <div class="layui-input-inline" style="width:160px;">
                                <select id="pattern_select" lay-filter="pattern">
                                    {volist name="pattern" id="v"}
                                    <option value="{$v.rule}" {if $v.rule==$model.pattern}selected{/if}>{$key}</option>
                                    {/volist}
                                </select>
                            </div>
                            <div class="layui-input-inline" style="width:260px;">
                                <input type="text" id="pattern" name="form[pattern]" value="{$model.pattern|default=''}" autocomplete="off" placeholder="" class="layui-input">
                            </div>
                            <label class="layui-form-label">失败提示</label>
                            <div class="layui-input-inline" style="width:260px;">
                                <input type="text" id="errortip" name="form[errortip]" value="{$model.errortip|default=''}" autocomplete="off" placeholder="" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">数据库语句</label>
                            <div class="layui-input-inline" style="width:180px;">
                                <select id="select_sql" lay-filter="sql">
                                    {volist name="sql" id="v"}
                                    <option value="{$v}" {if $v==$model.sql}selected{/if} >{$key}</option>
                                    {/volist}
                                </select>
                            </div>
                            <div class="layui-input-inline" style="width:360px;">
                                <input type="text" id="sql" name="form[sql]" value="{$model.sql|default=''}" autocomplete="off" placeholder="" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">如果为空，则不调整数据库表结构</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">字段类型</label>
                            <div class="layui-input-block" style="width:160px;">
                                <select name="form[type]" id="type" lay-filter="type">
                                    {volist name="type" id="v"}
                                    <option value="{$key}" >{$v}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div id="values"></div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">主表</label>
                            <div class="layui-input-block">
                                <input type="radio" name="form[ismain]" value="1" title="是" {$model.ismain?"checked":""} >
                                <input type="radio" name="form[ismain]" value="0" title="否" {$model.ismain?"":"checked"}>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">必填</label>
                            <div class="layui-input-block">
                                <input type="radio" name="form[isrequire]" value="1" title="是" {$model.isrequire?"checked":""} >
                                <input type="radio" name="form[isrequire]" value="0" title="否" {$model.isrequire?"":"checked"}>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">表单显示</label>
                            <div class="layui-input-block">
                                <input type="radio" name="form[show]" value="1" title="是" {$model.show?"checked":""} >
                                <input type="radio" name="form[show]" value="0" title="否" {$model.show?"":"checked"}>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">投稿显示</label>
                            <div class="layui-input-block">
                                <input type="radio" name="form[ispostshow]" value="1" title="是" {$model.ispostshow?"checked":""} >
                                <input type="radio" name="form[ispostshow]" value="0" title="否" {$model.ispostshow?"":"checked"}>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">列表显示</label>
                            <div class="layui-input-block">
                                <input type="radio" name="form[showintable]" value="1" title="是" {$model.showintable?"checked":""} >
                                <input type="radio" name="form[showintable]" value="0" title="否" {$model.showintable?"":"checked"}>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">排序</label>
                            <div class="layui-input-inline" style="width:260px;">
                                <input type="text" name="form[sort]" value="{$model.sort|default='50'}" autocomplete="off" placeholder="" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否启用</label>
                            <div class="layui-input-block">
                                <input type="radio" name="form[status]" value="1" title="是" {$model.status?"checked":""} >
                                <input type="radio" name="form[status]" value="0" title="否" {$model.status?"":"checked"}>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="commit">提交</button>
                                <button class="layui-btn layui-btn-primary" lay-submit lay-filter="reset">重置</button>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="textbox_config">
    <div class="layui-form-item">
        <label class="layui-form-label">默认值</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][defaultval]" autocomplete="off" placeholder="默认值" class="layui-input" value="{$model.configs.defaultval|default=''}">
        </div>
        <label class="layui-form-label">显示宽度</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][width]" autocomplete="off" placeholder="显示宽度" class="layui-input" value="{$model['configs']['width']|default=''}" />
        </div>
        <div class="layui-form-mid layui-word-aux">px</div>
    </div>
</script>
<script type="text/html" id="date_config">
    <div class="layui-form-item">
        <label class="layui-form-label">显示格式</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][format]" autocomplete="off" placeholder="显示宽度" class="layui-input" value="{$model.configs['format']|default='yyyy-MM-dd HH:mm:ss'}">
        </div>
    </div>
</script>
<script type="text/html" id="textarea_config">
    <div class="layui-form-item">
        <label class="layui-form-label">默认值</label>
        <div class="layui-input-block" style="min-width:400px;max-width:600px;height:100px;">
            <textarea type="text" name="form[configs][defaultval]" autocomplete="off" placeholder="默认值" class="layui-textarea">{$model.configs['defaultval']|default=''}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示宽度</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][width]" autocomplete="off" placeholder="显示宽度" class="layui-input" value="{$model.configs['width']|default=''}" />
        </div>
        <div class="layui-form-mid layui-word-aux">px</div>
    </div>
</script>
<script type="text/html" id="checkbox_config">
    <div class="layui-form-item">
        <label class="layui-form-label">默认值</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][defaultval]" autocomplete="off" placeholder="默认值" class="layui-input" value="{$model.configs['defaultval']|default=''}" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">可选项</label>
        <div class="layui-input-block" style="min-width:400px;max-width:600px;height:100px;">
            <textarea type="text" name="form[configs][values]" autocomplete="off" placeholder="键值对，格式为 id|val,id|val" class="layui-textarea">{$model.configs['values']|default=''}</textarea>
        </div>
    </div>
</script>
<script type="text/html" id="radio_config">
    <div class="layui-form-item">
        <label class="layui-form-label">默认值</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][defaultval]" autocomplete="off" placeholder="默认值" class="layui-input" value="{$model.configs['defaultval']|default=''}" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">可选项</label>
        <div class="layui-input-block" style="min-width:400px;max-width:600px;height:100px;">
            <textarea type="text" name="form[configs][values]" autocomplete="off" placeholder="键值对，格式为 id|val,id|val" class="layui-textarea">{$model.configs['values']|default=''}</textarea>
        </div>
    </div>
</script>
<script type="text/html" id="select_config">
    <div class="layui-form-item">
        <label class="layui-form-label">默认值</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][defaultval]" autocomplete="off" placeholder="默认值" class="layui-input" value="{$model.configs['defaultval']|default=''}" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">可选项</label>
        <div class="layui-input-block" style="min-width:400px;max-width:600px;height:100px;">
            <textarea type="text" name="form[configs][values]" autocomplete="off" placeholder="键值对，格式为 id|val,id|val" class="layui-textarea">{$model.configs['values']|default=''}</textarea>
        </div>
    </div>
</script>
<script type="text/html" id="file_config">
    <div class="layui-form-item">
        <label class="layui-form-label">最大限制</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][maxsize]" autocomplete="off" placeholder="默认值" class="layui-input" value="{$model.configs['maxsize']|default='2048'}" />
        </div>
        <div class="layui-form-mid layui-word-aux">KB</div>
    </div>
</script>
<script type="text/html" id="combotree_config">
    <div class="layui-form-item">
        <label class="layui-form-label">默认值</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][defaultval]" autocomplete="off" placeholder="默认值" class="layui-input" value="{$model.configs['defaultval']|default=''}" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数据源</label>
        <div class="layui-input-inline" style="width:400px;">
            <input type="text" name="form[configs][url]" autocomplete="off" placeholder="数据来源网址，数据为list形式即可，前台通过js转换为树结构" class="layui-input" value="{$model.configs['url']|default=''}" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">节点名</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][idkey]" autocomplete="off" placeholder="idkey" class="layui-input" value="{$model.configs['idkey']|default=''}" />
        </div>
        <label class="layui-form-label">根节点值</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][root]" autocomplete="off" placeholder="rootvalue" class="layui-input" value="{$model.configs['root']|default=''}" />
        </div>
        <label class="layui-form-label">父节点名</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][pidkey]" autocomplete="off" placeholder="父节点名称" class="layui-input" value="{$model.configs['pidkey']|default=''}" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文字名</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][namekey]" autocomplete="off" placeholder="namekey" class="layui-input" value="{$model.configs['namekey']|default=''}" />
        </div>
        <label class="layui-form-label">宽度</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][width]" autocomplete="off" placeholder="显示宽度" class="layui-input" value="{$model.configs['width']|default=''}" />
        </div>
        <div class="layui-form-mid layui-word-aux">px</div>
    </div>
</script>
<script type="text/html" id="image_config">
    <div class="layui-form-item">
        <label class="layui-form-label">最大限制</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][maxsize]" autocomplete="off" placeholder="默认值" class="layui-input" value="{$model.configs['maxsize']|default='2048'}" />
        </div>
        <div class="layui-form-mid layui-word-aux">KB</div>
        <label class="layui-form-label">图片类型</label>
        <div class="layui-input-inline">
            <input type="text" name="form[configs][extension]" autocomplete="off" placeholder="默认值" class="layui-input" value="{$model.configs['extension']|default='jpg,png,gif,bmp,jpeg'}" />
        </div>
    </div>
</script>
<script>
    layui.use(['form','element','laytpl'],function(){
        var form = layui.form;
        var element = layui.element;
        var laytpl = layui.laytpl;

        form.on('select(pattern)', function(data){
            $("#pattern").val(data.value);
        });
        form.on('select(sql)', function(data){
            $("#sql").val(data.value);
        });
        form.on('select(type)', function(data){
            var renderhtml = $("#"+data.value+"_config").html();
            if(renderhtml == undefined)
                renderhtml = '';
            $("#values").html(renderhtml);
        });
        $("#type").next(".layui-form-select").find("dd[lay-value='{$model.type|default=''}']").trigger('click');

        form.on('submit(commit)', function(obj){
            $.post({
                url:document.URL
                ,type:'post'
                ,data: obj.field
                ,success:function(res){
                    if(res.code == 1){
                        layer.msg(res.msg, {
                            offset: '15px'
                            ,icon: 1
                            ,time: 1000
                        }, function(){
                            location.href = res.url;
                        });
                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
        });

    });
</script>
{/block}